{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d7f752a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import netCDF4 as nc\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "from datetime import datetime, timedelta\n",
    "from netCDF4 import Dataset\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fa9bf7e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Open the NetCDF file\n",
    "file_path = 'C:\\\\Users\\\\magda\\\\Master_Thesis\\\\MMR\\\\20240503_100000.nc'\n",
    "dataset = nc.Dataset(file_path, mode='r')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "81572be1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NetCDF Dataset Information:\n",
      "<class 'netCDF4._netCDF4.Dataset'>\n",
      "root group (NETCDF4_CLASSIC data model, file format HDF5):\n",
      "    Conventions: CF/Radial\n",
      "    version: 1.3\n",
      "    title: METEK MRR Pro Data\n",
      "    references: \n",
      "    field_names: Za,Z,Zea,Ze,RR,LWC,PIA,VEL,WIDTH,SNR,spectrum_reflectivity,N\n",
      "    institution: Delft University of Technology\n",
      "    source: vertically profiling micro rain radar\n",
      "    history: Fri May  3 11:10:11 2024: /usr/bin/ncpdq -O -7 -L 5 --pck_map=dbl_flt --output=/data/202405/20240503/20240503_100000.nc /data/202405/20240503/20240503_100000.nc\n",
      "Fri May  3 11:10:09 2024: /usr/bin/ncap2 -O -s latitude=double(52.725515);longitude=double(4.775374);altitude=double(1) --output=/data/202405/20240503/20240503_100000.nc /data/202405/20240503/20240503_100000.nc\n",
      "Fri May  3 11:10:08 2024: /usr/bin/ncks -C -x -v azimuth,elevation,instrument_type,sweep_end_ray_index,sweep_mode,sweep_number,sweep_start_ray_index,fixed_angle --overwrite --output=/data/202405/20240503/20240503_100000.nc /data/202405/20240503/20240503_100000.nc\n",
      "Fri May  3 11:10:08 2024: /usr/bin/ncatted -O -a comment,global,o,c,REFORM campaign -a contributors,global,o,c,Marc Schleiss, Saverio Guzzo, Rob Mackenzie, Andre Castro, Mahaut Sourzac -a frequency,global,o,c,24.23 GHz -a institution,global,o,c,Delft University of Technology -a instrument_firmware,global,o,c,MRR Pro 2.0.23 -a instrument_id,global,o,c,MRRPro8 -a instrument_name,global,o,c,METEK MRR Pro -a instrument_serial_number,global,o,c,0510056436 -a instrument_type,global,o,c,MRR Pro by Metek GmbH -a sensor_name,global,o,c,MRR001 -a project_name,global,o,c,https://ruisdael-observatory.nl/ -a sampling_frequency,global,o,c,500 kHz -a site_name,global,o,c,Warmenhuizen -a source,global,o,c,vertically profiling micro rain radar -a wavelength,global,o,c,1.238 cm -a license,global,o,c,https://creativecommons.org/licenses/by-sa/4.0/ --output=/data/202405/20240503/20240503_100000.nc /data/202405/20240503/20240503_100000.nc\n",
      "\n",
      "    comment: REFORM campaign\n",
      "    instrument_name: METEK MRR Pro\n",
      "    site_name: Warmenhuizen\n",
      "    contributors: Marc Schleiss, Saverio Guzzo, Rob Mackenzie, Andre Castro, Mahaut Sourzac\n",
      "    frequency: 24.23 GHz\n",
      "    instrument_firmware: MRR Pro 2.0.23\n",
      "    instrument_id: MRRPro8\n",
      "    instrument_serial_number: 0510056436\n",
      "    instrument_type: MRR Pro by Metek GmbH\n",
      "    sensor_name: MRR001\n",
      "    project_name: https://ruisdael-observatory.nl/\n",
      "    sampling_frequency: 500 kHz\n",
      "    wavelength: 1.238 cm\n",
      "    license: https://creativecommons.org/licenses/by-sa/4.0/\n",
      "    NCO: netCDF Operators version 4.9.7 (Homepage = http://nco.sf.net, Code = http://github.com/nco/nco)\n",
      "    dimensions(sizes): n_spectra(128), spectrum_n_samples(64), time(360), range(128), string_length(128)\n",
      "    variables(dimensions): float64 latitude(), float64 longitude(), float32 altitude(), float32 D(n_spectra, spectrum_n_samples), float32 LWC(time, range), float32 ML(time, range), float32 N(time, n_spectra, spectrum_n_samples), float32 PIA(time, range), float32 RR(time, range), float32 SNR(time, range), float32 VEL(time, range), float32 WIDTH(time, range), float32 Z(time, range), float32 Za(time, range), float32 Ze(time, range), float32 Zea(time, range), float32 calibration_constant(), float32 doppler_shift_spectrum(), int32 index_spectra(time, range), float32 range(range), float32 spectrum_raw(time, n_spectra, spectrum_n_samples), float64 time(time), |S1 time_coverage_end(string_length), |S1 time_coverage_start(string_length), |S1 time_reference(string_length), float32 transfer_function(range), int32 volume_number()\n",
      "    groups: \n",
      "\n",
      "Global Attributes:\n",
      "Conventions: CF/Radial\n",
      "version: 1.3\n",
      "title: METEK MRR Pro Data\n",
      "references: \n",
      "field_names: Za,Z,Zea,Ze,RR,LWC,PIA,VEL,WIDTH,SNR,spectrum_reflectivity,N\n",
      "institution: Delft University of Technology\n",
      "source: vertically profiling micro rain radar\n",
      "history: Fri May  3 11:10:11 2024: /usr/bin/ncpdq -O -7 -L 5 --pck_map=dbl_flt --output=/data/202405/20240503/20240503_100000.nc /data/202405/20240503/20240503_100000.nc\n",
      "Fri May  3 11:10:09 2024: /usr/bin/ncap2 -O -s latitude=double(52.725515);longitude=double(4.775374);altitude=double(1) --output=/data/202405/20240503/20240503_100000.nc /data/202405/20240503/20240503_100000.nc\n",
      "Fri May  3 11:10:08 2024: /usr/bin/ncks -C -x -v azimuth,elevation,instrument_type,sweep_end_ray_index,sweep_mode,sweep_number,sweep_start_ray_index,fixed_angle --overwrite --output=/data/202405/20240503/20240503_100000.nc /data/202405/20240503/20240503_100000.nc\n",
      "Fri May  3 11:10:08 2024: /usr/bin/ncatted -O -a comment,global,o,c,REFORM campaign -a contributors,global,o,c,Marc Schleiss, Saverio Guzzo, Rob Mackenzie, Andre Castro, Mahaut Sourzac -a frequency,global,o,c,24.23 GHz -a institution,global,o,c,Delft University of Technology -a instrument_firmware,global,o,c,MRR Pro 2.0.23 -a instrument_id,global,o,c,MRRPro8 -a instrument_name,global,o,c,METEK MRR Pro -a instrument_serial_number,global,o,c,0510056436 -a instrument_type,global,o,c,MRR Pro by Metek GmbH -a sensor_name,global,o,c,MRR001 -a project_name,global,o,c,https://ruisdael-observatory.nl/ -a sampling_frequency,global,o,c,500 kHz -a site_name,global,o,c,Warmenhuizen -a source,global,o,c,vertically profiling micro rain radar -a wavelength,global,o,c,1.238 cm -a license,global,o,c,https://creativecommons.org/licenses/by-sa/4.0/ --output=/data/202405/20240503/20240503_100000.nc /data/202405/20240503/20240503_100000.nc\n",
      "\n",
      "comment: REFORM campaign\n",
      "instrument_name: METEK MRR Pro\n",
      "site_name: Warmenhuizen\n",
      "contributors: Marc Schleiss, Saverio Guzzo, Rob Mackenzie, Andre Castro, Mahaut Sourzac\n",
      "frequency: 24.23 GHz\n",
      "instrument_firmware: MRR Pro 2.0.23\n",
      "instrument_id: MRRPro8\n",
      "instrument_serial_number: 0510056436\n",
      "instrument_type: MRR Pro by Metek GmbH\n",
      "sensor_name: MRR001\n",
      "project_name: https://ruisdael-observatory.nl/\n",
      "sampling_frequency: 500 kHz\n",
      "wavelength: 1.238 cm\n",
      "license: https://creativecommons.org/licenses/by-sa/4.0/\n",
      "NCO: netCDF Operators version 4.9.7 (Homepage = http://nco.sf.net, Code = http://github.com/nco/nco)\n",
      "\n",
      "Dimensions:\n",
      "n_spectra: 128\n",
      "spectrum_n_samples: 64\n",
      "time: 360\n",
      "range: 128\n",
      "string_length: 128\n",
      "\n",
      "Variables:\n",
      "\n",
      "Variable Name: latitude\n",
      "Dimensions: ()\n",
      "Shape: ()\n",
      "Data Type: float64\n",
      "    units: degrees_north\n",
      "\n",
      "Variable Name: longitude\n",
      "Dimensions: ()\n",
      "Shape: ()\n",
      "Data Type: float64\n",
      "    units: degrees_east\n",
      "\n",
      "Variable Name: altitude\n",
      "Dimensions: ()\n",
      "Shape: ()\n",
      "Data Type: float32\n",
      "    units: meters\n",
      "\n",
      "Variable Name: D\n",
      "Dimensions: ('n_spectra', 'spectrum_n_samples')\n",
      "Shape: (128, 64)\n",
      "Data Type: float32\n",
      "    standard_name: drop_sizes\n",
      "    long_name: \n",
      "    units: 1\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    index_var_name: \n",
      "    block_avg_length: 0\n",
      "    is_spectrum: true\n",
      "\n",
      "Variable Name: LWC\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: mass_concentration_of_liquid_water_in_air\n",
      "    long_name: \n",
      "    units: g m-3\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: ML\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: melting_layer\n",
      "    long_name: \n",
      "    units: \n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: N\n",
      "Dimensions: ('time', 'n_spectra', 'spectrum_n_samples')\n",
      "Shape: (360, 128, 64)\n",
      "Data Type: float32\n",
      "    standard_name: drop_size_distribution\n",
      "    long_name: \n",
      "    units: 1\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    index_var_name: \n",
      "    block_avg_length: 0\n",
      "    is_spectrum: true\n",
      "\n",
      "Variable Name: PIA\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: path_integrated_rain_attenuation\n",
      "    long_name: \n",
      "    units: dB\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: RR\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: rainfall_rate\n",
      "    long_name: \n",
      "    units: mm h-1\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: SNR\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: signal_to_noise_ratio\n",
      "    long_name: \n",
      "    units: dB\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: VEL\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: radial_velocity_of_scatterers_towards_instrument\n",
      "    long_name: \n",
      "    units: m s-1\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: true\n",
      "    fold_limit_lower: -0.0\n",
      "    fold_limit_upper: 11.893999099731445\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: WIDTH\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: doppler_spectrum_width\n",
      "    long_name: \n",
      "    units: m/s\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: Z\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: log_reflectivity\n",
      "    long_name: \n",
      "    units: dBZ\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: Za\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: log_attenuated_reflectivity\n",
      "    long_name: \n",
      "    units: dBZ\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: Ze\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: equivalent_reflectivity_factor\n",
      "    long_name: \n",
      "    units: dBZ\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: Zea\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: float32\n",
      "    standard_name: attenuated_equivalent_reflectivity_factor\n",
      "    long_name: \n",
      "    units: dBZ\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: false\n",
      "\n",
      "Variable Name: calibration_constant\n",
      "Dimensions: ()\n",
      "Shape: ()\n",
      "Data Type: float32\n",
      "\n",
      "Variable Name: doppler_shift_spectrum\n",
      "Dimensions: ()\n",
      "Shape: ()\n",
      "Data Type: float32\n",
      "\n",
      "Variable Name: index_spectra\n",
      "Dimensions: ('time', 'range')\n",
      "Shape: (360, 128)\n",
      "Data Type: int32\n",
      "    standard_name: index variable spectra\n",
      "    long_name: \n",
      "    units: \n",
      "    _FillValue: -2147483648\n",
      "    coordinates: elevation azimuth range\n",
      "    field_folds: false\n",
      "    fold_limit_lower: 0.0\n",
      "    fold_limit_upper: 0.0\n",
      "    thresholding_xml: \n",
      "    legend_xml: \n",
      "    is_discreet: true\n",
      "\n",
      "Variable Name: range\n",
      "Dimensions: ('range',)\n",
      "Shape: (128,)\n",
      "Data Type: float32\n",
      "    standard name: projection_range_coordinate\n",
      "    long_name: range_to_measurement_volume\n",
      "    units: meters\n",
      "    spacing_is_constant: true\n",
      "    meters_to_center_of_first_gate: 0.0\n",
      "    meters_between_gates: 35.0\n",
      "    axis: radial_range_coordinate\n",
      "\n",
      "Variable Name: spectrum_raw\n",
      "Dimensions: ('time', 'n_spectra', 'spectrum_n_samples')\n",
      "Shape: (360, 128, 64)\n",
      "Data Type: float32\n",
      "    standard_name: log_attenuated_power\n",
      "    long_name: \n",
      "    units: dB\n",
      "    _FillValue: nan\n",
      "    coordinates: elevation azimuth range\n",
      "    index_var_name: \n",
      "    block_avg_length: 0\n",
      "    is_spectrum: true\n",
      "\n",
      "Variable Name: time\n",
      "Dimensions: ('time',)\n",
      "Shape: (360,)\n",
      "Data Type: float64\n",
      "    standard name: time\n",
      "    long_name: time_in_seconds_since_volume_start\n",
      "    units: seconds since 1970-01-01T00:00:00Z\n",
      "    calendar: standard\n",
      "\n",
      "Variable Name: time_coverage_end\n",
      "Dimensions: ('string_length',)\n",
      "Shape: (128,)\n",
      "Data Type: |S1\n",
      "\n",
      "Variable Name: time_coverage_start\n",
      "Dimensions: ('string_length',)\n",
      "Shape: (128,)\n",
      "Data Type: |S1\n",
      "\n",
      "Variable Name: time_reference\n",
      "Dimensions: ('string_length',)\n",
      "Shape: (128,)\n",
      "Data Type: |S1\n",
      "\n",
      "Variable Name: transfer_function\n",
      "Dimensions: ('range',)\n",
      "Shape: (128,)\n",
      "Data Type: float32\n",
      "\n",
      "Variable Name: volume_number\n",
      "Dimensions: ()\n",
      "Shape: ()\n",
      "Data Type: int32\n"
     ]
    }
   ],
   "source": [
    "# Print dataset information\n",
    "print(\"NetCDF Dataset Information:\")\n",
    "print(dataset)\n",
    "\n",
    "# Print global attributes\n",
    "print(\"\\nGlobal Attributes:\")\n",
    "for attr_name in dataset.ncattrs():\n",
    "    print(f\"{attr_name}: {getattr(dataset, attr_name)}\")\n",
    "\n",
    "# Print dimensions\n",
    "print(\"\\nDimensions:\")\n",
    "for dim_name, dim in dataset.dimensions.items():\n",
    "    print(f\"{dim_name}: {len(dim)}\")\n",
    "\n",
    "# Print variables and their attributes\n",
    "print(\"\\nVariables:\")\n",
    "for var_name, var in dataset.variables.items():\n",
    "    print(f\"\\nVariable Name: {var_name}\")\n",
    "    print(f\"Dimensions: {var.dimensions}\")\n",
    "    print(f\"Shape: {var.shape}\")\n",
    "    print(f\"Data Type: {var.dtype}\")\n",
    "    for attr_name in var.ncattrs():\n",
    "        print(f\"    {attr_name}: {getattr(var, attr_name)}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
